package com.itheima.tliasbackend.controller;

import com.itheima.tliasbackend.utils.AliOSSUtils;
import com.itheima.tliasbackend.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * UploadController
 *
 * @author liliudong
 * @version 1.0
 * @description
 * @date 2023/5/23 11:28
 */
@Slf4j
@RestController
public class UploadController {

    @Autowired
    private AliOSSUtils aliOSSUtils;

    @PostMapping("/upload")
    public Result upload(String name, MultipartFile image) throws IOException {
        log.info("文件接收到了: {}, {}", name, image);
        String uploadUrl = aliOSSUtils.upload(image);
        log.info("文件上传成功，地址是：{}", uploadUrl);
        return Result.success(uploadUrl);
    }
}
